#include "Input.h"

// ********************** //
/* MouseState Definitions */
MouseState::MouseState() {
	isLeftDown = isRightDown = isMiddleDown = false;
	scroll_delta = 0;
	position.set(0, 0);
	previous_position.set(0, 0);
}

void MouseState::SetPosition (int newX, int newY) {
	previous_position = position;
	position.set((float)newX, (float)newY);
}

VectorXYZ MouseState::Direction () {
	VectorXYZ temp = Difference();
	temp.Normalize();
	return temp;
}

VectorXYZ MouseState::Difference () {
	VectorXYZ temp;
	temp.set(position.x - previous_position.x, position.y - previous_position.y);
	return temp;
}

// ************************ //
/* KeyboardState Definitions */

bool KeyboardState::isKeyDown (unsigned int Key) const {
	if (!active_keys.empty()) {
		for (int i = 0; i < (int)active_keys.size(); i++) {
			if (active_keys[i] == Key) {
				return true;
			}
		}
	}
	return false;
}

void KeyboardState::AddKey (unsigned int Key) {
	if (!isKeyDown(Key)) 
		active_keys.push_back(Key);
}

void KeyboardState::AddKey (char Key) {
	if (!isKeyDown(Key)) 
		active_keys.push_back((unsigned int)Key);
}

void KeyboardState::RemoveKey (unsigned int Key) {
	if (!active_keys.empty()) {
		for (int i = 0; i < (int)active_keys.size(); i++) {
			if (active_keys[i] == Key) {
				active_keys.erase(active_keys.begin() + i);
			}
		}
	}
}

void KeyboardState::RemoveKey (char Key) {
	unsigned int key = (unsigned int)Key;
	
	if (!active_keys.empty()) {
		for (int i = 0; i < (int)active_keys.size(); i++) {
			if (active_keys[i] == key) {
				active_keys.erase(active_keys.begin() + i);
			}
		}
	}
}

// ************************* //

KeyboardState Keyboard;
MouseState Mouse;